package aviator.test01;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPObject;
import com.googlecode.aviator.AviatorEvaluator;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.junit.Test;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.Map;
import java.util.concurrent.Executors;

/**
 * @program RCS
 * @description: 意图参数
 * @author: zhanglu
 * @create: 2020-11-23 18:53:00
 */
@Data
@Accessors(chain = true)
public class IntentionParams {

    //key
    private String k;
    //value
    private String v;
    //当前次数
    private Integer c;

    /**
     * 导入java静态方法
     */
    @Test
    public void test01() throws Exception {
        String responseStr = "{\"code\":1,\"data\":{\"name\":\"张三\",\"age\":1,\"phone\":\"17356524108\",\"idCard\":\"340302199701080014\",\"ticket\":{\"trainNumber\":\"G1703\",\"startPoint\":\"南京\",\"endPoint\":\"蚌埠\",\"startDate\":\"2020-11-11 09:00:00\",\"endDate\":\"2020-11-11 09:45:00\"},\"history\":[{\"trainNumber\":\"G1701\",\"startPoint\":\"蚌埠\",\"endPoint\":\"合肥\",\"startDate\":\"2020-11-09 14:30:00\",\"endDate\":\"2020-11-09 15:25:00\",\"sss\":[{\"id\":\"1\",\"ss\":[\"s\"]}]},{\"trainNumber\":\"G1702\",\"startPoint\":\"合肥\",\"endPoint\":\"南京\",\"startDate\":\"2020-11-09 22:30:00\",\"endDate\":\"2020-11-09 23:15:00\"}]}}";
        cn.hutool.json.JSONObject map = JSONUtil.parseObj(responseStr);
//        Object execute = AviatorEvaluator.compile("'{\"name\":\"'+data.name+'\", \"num\":\"'+data.history[0].trainNumber+'\"}'").execute(map);
        Object execute = AviatorEvaluator.compile("println(__args__)").execute(map);
        execute = AviatorEvaluator.compile("#`data.history[0].sss[0].id`").execute(map);
        System.out.println(execute);
//        Map map1 = JSONObject.parseObject(execute.toString(), Map.class);
//        System.out.println(1);
    }

}
